import Mock from 'mockjs';
import {bannerList} from '../resources/banner';
let _bannerList = bannerList;

export default{
    list:config => {
        let {page, bannerName, bannerType, addDate} = config.params;

        let mockBanners = _bannerList.filter(banner => {
            if (addDate && banner.addDate !== addDate) return false;
            if (bannerName && banner.bannerName !== bannerName) return false;
            if (bannerType && banner.bannerType !== bannerType) return false;
            return true;
        });
        if (page === 0) page++;
        mockBanners = mockBanners.filter((u, index) => index < 20 * page && index >= 20 * (page - 1));
        return new Promise((resolve, reject) => {
            resolve([200, {
                total: _bannerList.length,
                TableData: mockBanners
            } ]);
        });
    },
    add:config => {
        let { bannerName, bannerType, url, bannerOrder } = JSON.parse(config.data);
        _bannerList.push({
            id: Mock.Random.guid(),
            bannerName,
            bannerType,
            url,
            bannerOrder,
            date: new Date(time).getTime(),
            status:1
        });

    }
}